# - Try to find protobuf
# TO MERGE: /usr/share/cmake-3.15/Modules/FindProtobuf.cmake
#

set(Protobuf_VERSION 2.6.1)

find_path(Protobuf_INCLUDE_DIR google/protobuf message.h
   HINTS ${PREBUILT_LIBRARIES}/protobuf-${Protobuf_VERSION}/include
)

find_library(Protobuf_LIBRARY NAMES libprotobuf.a
   HINTS ${PREBUILT_LIBRARIES}/protobuf-${Protobuf_VERSION}/linux/${CMAKE_SYSTEM_PROCESSOR}/lib
)

find_library(Protobuf_LITE_LIBRARY NAMES libprotobuf-lite.a
   HINTS ${PREBUILT_LIBRARIES}/protobuf-${Protobuf_VERSION}/linux/${CMAKE_SYSTEM_PROCESSOR}/lib
)

find_library(Protobuf_PROTOC_LIBRARY NAMES libprotoc.so
   HINTS ${PREBUILT_LIBRARIES}/protobuf-${Protobuf_VERSION}/linux/${CMAKE_SYSTEM_PROCESSOR}/bin
)

set(Protobuf_LIBRARIES ${Protobuf_LIBRARY} )
set(Protobuf_LITE_LIBRARIES ${Protobuf_LITE_LIBRARY} )
set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIR} )
set(Protobuf_USE_STATIC_LIBS "ON" )
set(Protobuf_PROTOC_EXECUTABLE ${PREBUILT_LIBRARIES}/protobuf-${Protobuf_VERSION}/bin/protoc )
set(Protobuf_PROTOC_LIBRARIES ${Protobuf_PROTOC_LIBRARY} )

include(FindPackageHandleStandardArgs)

# handle the QUIETLY and REQUIRED arguments and set Protobuf_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(Protobuf DEFAULT_MSG Protobuf_LIBRARY Protobuf_INCLUDE_DIR)

mark_as_advanced(Protobuf_INCLUDE_DIR ${Protobuf_INCLUDE_DIR} )

## define protobuf_generate_cpp
include("${CMAKE_ROOT}/Modules/FindProtobuf.cmake")
